//
//  BookingCell.m
//  mUBB
//
//  Created by Cosmin Stirbu on 3/4/13.
//  Copyright (c) 2013 Cosmin Stirbu. All rights reserved.
//

#import "BookingCell.h"
#import "Utils.h"
#import "ConfigurationManager.h"
#import "BookingsManager.h"

#define DATE_FORMAT @"EE dd - MMM - yyyy"
#define TIME_FORMAT @"HH:mm"

@implementation BookingCell

@synthesize booking, dateLabel, timeLabel, typeOfClassLabel, teacherLabel, placeLabel, studyGroupsLabel, calendarImageView;

- (void)awakeFromNib {
    dateLabel.textColor = [Utils colorWithHexString:[[ConfigurationManager instance] UIConfigValueForKey:@"booking_cell_date_text_color"]];
    timeLabel.textColor = [Utils colorWithHexString:[[ConfigurationManager instance] UIConfigValueForKey:@"booking_cell_date_text_color"]];
    teacherLabel.textColor = [Utils colorWithHexString:[[ConfigurationManager instance] UIConfigValueForKey:@"booking_cell_other_text_color"]];
    placeLabel.textColor = [Utils colorWithHexString:[[ConfigurationManager instance] UIConfigValueForKey:@"booking_cell_other_text_color"]];
    studyGroupsLabel.textColor = [Utils colorWithHexString:[[ConfigurationManager instance] UIConfigValueForKey:@"booking_cell_other_text_color"]];
    typeOfClassLabel.textColor = [Utils colorWithHexString:[[ConfigurationManager instance] UIConfigValueForKey:@"booking_cell_type_of_class_color"]];
    calendarImageView.image = [UIImage imageNamed:[[ConfigurationManager instance] UIConfigValueForKey:@"calendar_image"]];
    
}

// Custom Booking Setter
- (void)setBooking:(Booking *)aBooking {
    booking = aBooking;
    
    // Set up the UI
    
    // Date Time
    dateLabel.text = [Utils stringFromDate:booking.startDate withFormat:DATE_FORMAT];
    
    // Time Label
    timeLabel.text = [NSString stringWithFormat:@"%@ - %@",[Utils stringFromDate:booking.startDate withFormat:TIME_FORMAT], [Utils stringFromDate:booking.endDate withFormat:TIME_FORMAT]];
    
    // Teacher
    teacherLabel.text = [NSString stringWithFormat:@"%@ %@", booking.teacher.firstName, booking.teacher.lastName];

    
    // Place
    placeLabel.text = [NSString stringWithFormat:@"%@ %@, %@", NSLocalizedString(@"BOOKING_CELL_PLACE", nil), booking.room.name, booking.room.building.name];
    NSMutableString *studyGroupsText = [NSMutableString stringWithString:NSLocalizedString(@"BOOKING_CELL_STUDY_GROUPS", nil)];
    [studyGroupsText appendFormat:@" %@", [[BookingsManager instance] stringWithBookingStudyGroups:booking.studyGroups]];
     studyGroupsLabel.text = studyGroupsText;
    
    // Type of class
    if ([booking.typeOfClass isOtherType]) {
        typeOfClassLabel.text = booking.typeOfClass.name;
        [typeOfClassLabel setHidden:NO];
    } else {
        [typeOfClassLabel setHidden:YES];
    }
    
    // Calendar Image
    calendarImageView.hidden = ![[BookingsManager instance] bookingIsInCalendar:booking];
    
}

@end
